if(!Date.prototype.Format)
{
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    };
};

//全站Ajax设置无缓存
$.ajaxSetup({
    cache: false
});
$(function () {
    // 标题下面没有表单可填写，就隐藏标题
    var $fieldCaption=$(".tabel_col .caption");
    $fieldCaption.each(function(index, el) {
        if ($(this).next("div").children('div').hasClass('fieldBox')) return;
        var $fieldBox=$(this).next(".fieldBox");
        if (!$fieldBox.length) $(this).hide();
    });
    $(".iframeBody iframe").load(function() {
        try{
            $(this).contents().find("body").addClass('iframeBody_L2')
        }
        catch(err){}
    });
    $(".liger_tip").ligerTip();
    $(".l-dialog-btn-cancel").click(function() {
        var ligeruiID=$(this).parents(".l-dialog").attr('ligeruiid');
        if (ligeruiID) {
            var dialog=liger.get(ligeruiID);
            dialog.hide();
        };
        if (frameElement && frameElement.dialog) frameElement.dialog.hidden();
    });

    // 搜索框 按回车键的时候 可搜索（只有一个输入框和按钮）
    $("form.titSearchBar").each(function(index, el) {
        if ($(this).find('input[type=text]').length==1) {
            $(this).submit(function(event) {
                event.preventDefault();
                $(this).find('.sq-search-button').click();
            });
        };
    });
    //点击F5键，或者Crtl+R键 刷新的时候，只刷新当前Tab
    $(document).keydown(function(event) {
        var navTab=top.tab;
        if (!navTab) return;
        var keycode=event.keyCode;
        if (keycode==116) {
            event.preventDefault();
            navTab.reload(navTab.getSelectedTabItemID());
        }
        //Ctrl键和r键组合 导致刷新页面
        // else if (keycode==17) {
        //     $(document).keydown(function(event) {
        //         var keycode2=event.keyCode;
        //         if (keycode2==82) {
        //             event.preventDefault();
        //             navTab.reload(navTab.getSelectedTabItemID());
        //         };
        //     });
        // };
    });
    // 按“回车键”，触发搜索（针对.ui-textbox）
    $(".searchArea .ui-textbox").on('keydown', function(event) {
        if (event.keyCode == 13) {
            event.preventDefault();
            $(this).parents(".searchArea").find('#searchBtn').click();
        };
    });
    $('[data-tofix]').each(function(index, el) {
        var Precision = $(this).data('tofix');
        $(this).toFixNumber(Precision,
            {
                onToFix: function () {
                    top.$.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不能超过"+Precision+"位数！"});
                }
            }
        );
    });
    //表单的label超出范围 显示省略号，并已toolTip的方式显示全部内容
    $('[role="ligertip"]').each(function(index, el) {
        var content = $(el).text();
        $(el).attr('title', content).grid_ligerTip();
    });
    $('.fieldset1.tabel_col .fieldBox .label').each(function(index, el) {
        if (el.scrollWidth <= el.clientWidth) return;
        if ($(el).attr('role') == 'ligertip') return; //手动添加了 就忽略
        if ($(el).attr('role') == 'textclip') return; //role="textclip"若允许折行 就忽略
        var content = $(el).text();
        $(el).attr('title', content).grid_ligerTip();
    });
    // 表单的label超出范围时 是否允许折行
    $('[role="textclip"]').each(function(index, el) {
        $(el).css({
            'white-space': 'normal',
            'text-overflow': 'clip'
        });
    });
    //ligerGrid里面的下拉框，绑定事件
    //注：render的时候用SQ.dropLinks()方法，把里面的按钮（a）包装一下
    $('.sq-grid').on('click', '.dropLinks .dropBtn', function(e) {
        e.preventDefault();
        e.stopPropagation();
        var $dropLinks = $(this).parent('.dropLinks'),
            $dropList = $(this).siblings('.dropList').clone(),
            pos_top=$(this).offset().top + $(this).outerHeight(),
            pos_right=$(window).width() - $(this).offset().left - $(this).outerWidth();
        if ($dropLinks.hasClass('open')) {
            _close();
            return;
        } else {
            _close();
            $dropLinks.addClass('open');
        };
        $dropList.appendTo('body').addClass('Fix_dropLinks').css({
            top: pos_top,
            right: pos_right
        });
        $(document).click(function(event) {
            _close()
        });
        function _close() {
            $('.Fix_dropLinks').remove();
            $('.dropLinks').removeClass('open')
        }
    });
})
/**
 * 嵌套子窗口（iframe），高度调整
 * 注：pageInApp 是一级之窗口创建的对象，作为二级之窗口调用的接口
 * 注：pageInTab 是一级子窗口里创建的标签组（如果有）（ligerTab对象）
 */
function SetIframe_height () {
    if (parent && parent.mainApp && parent.mainApp.parentTab && parent.mainApp.parentTab.onResize) {
        parent.mainApp.parentTab.onResize();
    }else
    if (parent && parent.pageInApp && parent.pageInApp.pageInTab && parent.pageInApp.pageInTab.onResize) {
        parent.pageInApp.pageInTab.onResize();
        if (top.mainApp && top.mainApp.parentTab && top.mainApp.parentTab.onResize) {
            top.mainApp.parentTab.onResize();
        }
    };
}
function GET_minIframeHeight () { //只针对有二级ligerTab | 用在了ligerTab的minIframeHeight设置上
    var minIframeHeight=$(parent.window).height()-172;
    return minIframeHeight;
}
// Dialog的内容是url 嵌入的时候，用来调整iframe高度
function SET_popupIframeHeight () {
    if (!$("body").hasClass('iframeBody_popup')) $("body").addClass('iframeBody_popup');
    $(frameElement).height($("html").outerHeight())
}
function Add_navTab (tabid, text, url, receive) {
    if (top && top.mainApp && top.mainApp.parentTab && top.mainApp.f_addTab) {
        top.mainApp.f_addTab(tabid, text, url);
        var iframe=top.$("#"+tabid).get(0);
        iframe.W2W = {callback: null, data: null};
        if (typeof(receive)=="function") { //如果有callback，就绑定到iframe对象上
            iframe.W2W.callback = receive;
        } else if(receive){
            iframe.W2W.data = receive;
        };
    }else{
        window.open(url);
    };
}
function Add_navTab_post(data, action, title, callback) {
    var timestamp = new Date().getTime()
    var iframe_id = 'post_iframe_' + timestamp
    var _title = title || timestamp.toString().slice(timestamp.toString().length - 2)
    var _form = $('<form id="myForm" method="post" target="'+iframe_id+'" action="'+action+'" style="height: 0; overflow: hidden;"></form>')
    var _keys = Object.keys(data)
    _keys.forEach(function (key) {
        _form.append('<input type="hidden" name="'+key+'" value="'+data[key]+'" />')
    })
    top.$('body').append(_form)
    Add_navTab(iframe_id, _title, '/', callback);
    _form.submit()
}
function Remove_navTab (tabid) {
    if (top && top.mainApp && top.mainApp.parentTab) {
        var TAB=top.mainApp.parentTab;
        if (tabid) {
            TAB.removeTabItem(tabid);
        }else{ //没有传tabid就默认关闭当前tab
            var currentTabid=TAB.getSelectedTabItemID();
            var callback = GET_W2Wcallback (currentTabid);
            TAB.removeTabItem(currentTabid);
            callback && callback(); //移除Tab之后，执行callback
        };
    }else{
        return;
    };
}
function GET_W2W (tabid) { //可以指定具体的tabid，如果没有指定，默认当前tab | Add_navTab()的时候添加的receive
    if (top.mainApp && top.mainApp.parentTab) {
        var TabID = tabid;
        if (tabid == undefined ) TabID=top.mainApp.parentTab.getSelectedTabItemID();
        return top.$("#"+TabID).get(0).W2W;
    }
}
function GET_W2Wcallback (tabid) { //可以指定具体的tabid，如果没有指定，默认当前tab | Add_navTab()的时候添加的receive
    if (top && top.mainApp && top.mainApp.parentTab) {
        var TabID = tabid;
        if (tabid == undefined ) TabID=top.mainApp.parentTab.getSelectedTabItemID();
        var Tabiframe=top.$("#"+TabID).get(0);
        if (Tabiframe.W2W && Tabiframe.W2W.callback) {
            var callback=Tabiframe.W2W.callback;
        }
        return callback;
    }
}
//金额 用逗号 隔开。数字格式化
function FormatMoney(s, n){
    n = n > 0 && n <= 20 ? n : 2;
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    var l = s.split(".")[0].split("").reverse(),
        r = s.split(".")[1];
    t = "";
    for(i = 0; i < l.length; i ++ )
    {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }
    return t.split("").reverse().join("") + "." + r;
}
//金额 用逗号 隔开 -- 还原
function ReformatMoney(s){
    return parseFloat(s.replace(/[^\d\.-]/g, ""));
}
//是否正整数
function isInteger(number){
    return number > 0 && String(number).split('.')[1] == undefined
}

//是否是数字
function isNumber(number){
    return typeof number === 'number'
}

//弹框提示
function ligerDialogWarn (info,timeout) {
    var dialog = $.ligerDialog.warn(info);
    if (timeout && isInteger(timeout)) {
        setTimeout(function () {
            dialog.hide();
        },timeout)
    };
    return dialog;
}
function ligerDialogSuc (info,timeout) {
    var dialog = $.ligerDialog.success(info);
    if (timeout && isInteger(timeout)) {
        setTimeout(function () {
            dialog.hide();
        },timeout)
    };
    return dialog;
}
function ligerDialogWait (info,timeout) {
    var dialog = $.ligerDialog.waitting(info);
    if (timeout && isInteger(timeout)) {
        setTimeout(function () {
            dialog.hide();
        },timeout)
    };
    return dialog;
}
$.ligerDialog.SQopen = function (p){
    var onLoaded_funcs = p.onLoaded ? [p.onLoaded] : []; //事件队列
    if (p.title == '') p.title = '&nbsp;';
    if (!p.top) p.top=$(top).scrollTop() + 30;
    if (p.fixButtons) {
        var onOk = function (item, Dialog) {
            if (p.onOk) {
                p.onOk();
            }else if (Dialog.onOk) {
                Dialog.onOk(); //在子页面里绑定 frameElement.dialog.onOk = function () {}
            }else{
                throw 'You should have a callback, that named onOk !'
            }
        };
        var onCancel = function (item, Dialog) {
            if (p.onCancel) {
                p.onCancel();
            }else if (Dialog.onCancel) {
                Dialog.onCancel(); //在子页面里绑定 frameElement.dialog.onCancel = function () {}
            }else{
                Dialog.close();
            }
        };
        p.buttons = [{
            text: $.ligerDefaults.DialogString.ok, onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
        }, {
            text: $.ligerDefaults.DialogString.cancel, onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
        }
        ];
    }
    onLoaded_funcs.push(function () {
        // 如果弹窗嵌入的iframe的body里没有.iframeBody_popup，就添加这个class
        if (!this.frame.$('body').hasClass('iframeBody_popup')) this.frame.$('body').addClass('iframeBody_popup');
    });
    if (p.autoFixHeight) {
        onLoaded_funcs.push(function () {
            // if (this.frame && this.frame.SET_popupIframeHeight) {this.frame.SET_popupIframeHeight()};
            //上面的代码改成如下 ^
            if (this.frame) this.jiframe.height(this.frame.$("html").outerHeight());
        });
        p.cls += ' autoFixHeight';
    };
    p.onLoaded = function () {
        for (var i = 0; i < onLoaded_funcs.length; i++) {
            onLoaded_funcs[i].call(this);
        };
    };
    return $.ligerDialog(p);
};
$.ligerDialog.SQalert = function (options){
    var _p={
        SQ_buttonYesText : "确定",
        SQ_showButtons : false,
        title: "提示",
        SQ_showTitle : false,
        content: "",
        SQ_timeout : 1500,
        SQ_type : null,
        cls: '',
        SQ_onBtnclick : null,
        top: null
    };
    // console.log($(window).scrollTop());
    $.extend(_p, options || {});
    var btnclick = function (item){
        _close()
        if (_p.SQ_onBtnclick && (typeof (_p.SQ_onBtnclick) == "function")){
            _p.SQ_onBtnclick(item.type);
        }
    };
    if (_p.SQ_showButtons) {
        _p.SQ_timeout=false;
        _p.cls += " hasAlertBtn "
        _p.buttons = [{ text: _p.SQ_buttonYesText, onclick: btnclick, type: 'yes' }];
    }
    _p.cls += " SQalert ";
    if (!_p.SQ_showTitle) {_p.cls += "noTitle "; _p.title="&nbsp;"}
    switch (_p.SQ_type){
        case "success":
            _p.cls += " alert_success "
            break;
        case "warning":
            _p.cls += " alert_warning "
            break;
        case "error":
            _p.cls += " alert_error "
            break;
        case "waitting":
            _p.cls += " alert_waitting "
            _p.content='<span class="loadingGif"></span> '+_p.content
            break;
    }
    p = {
        isHidden: true,
        allowClose: false,
        buttons: null
    };
    $.extend(p, _p);
    var dialog = $.ligerDialog(p);
    (function () {
        if (window == top) return;
        if(frameElement && frameElement.dialog) return;
        var topPos = 0,
            headNnav_H = top.headNnav_H ? top.headNnav_H : 82;
        if (_p.top != null) topPos = _p.top;
        else _p.top = topPos = 0.5 * ($(top).height() - headNnav_H - dialog.dialog.height()) + $(top).scrollTop() - 70;
        if (topPos < 0) _p.top = topPos = 0;
        dialog.dialog.css({top: topPos });
    })();
    if (_p.SQ_type=="waitting") return dialog;
    var $SQalertMask_El = $('<div class="l-SQalert-mask" style="display: block; position: fixed; left: 0; top: 0; width: 100%; height: 100%; background: none; overflow: hidden; z-index: 9199;"></div>')
    $("body").append($SQalertMask_El);
    var _close = function () {
        if(dialog) dialog.close();
        $SQalertMask_El.remove();
    }
    var _T = null
    if (_p.SQ_timeout && isInteger(_p.SQ_timeout) && (_T==null)) {
        _T=setTimeout(_close,_p.SQ_timeout)
    };
    $SQalertMask_El.click(function(event) {
        if (_p.SQ_showButtons) return false;
        event.preventDefault();
        event.stopPropagation();
        if(_T != null) {
            clearTimeout(_T);
            _T = null;
        };
        _close();
    });
};
$.ligerDialog.SQconfirm = function (content, title, callback){
    if (typeof (title) == "function")
    {
        callback = title;
        type = null;
    }
    var btnclick = function (item, Dialog)
    {
        Dialog.close();
        if (callback)
        {
            callback(item.type == 'ok');
        }
    };
    p = {
        cls: 'SQconfirm',
        type: 'question',
        content: content,
        top: $(top).scrollTop() + 30,
        verticalCenter: true,
        buttons: [
            {
                text: $.ligerDefaults.DialogString.yes, onclick: btnclick, type: 'ok', cls: 'l-dialog-btn-ok'
            }, {
                text: $.ligerDefaults.DialogString.no, onclick: btnclick, type: 'no', cls: 'l-dialog-btn-no'
            }
        ]
    };
    if (typeof (title) == "string" && title != "") p.title = title;
    $.extend(p, {
        showMax: false,
        showToggle: false,
        showMin: false
    });
    // return $.ligerDialog(p);
    var dialog = $.ligerDialog(p);
    (function () {
        if (window == top) return;
        if(frameElement && frameElement.dialog) return;
        var topPos = 0,
            headNnav_H = top.headNnav_H ? top.headNnav_H : 82;
        if (!p.verticalCenter) return;
        else p.top = topPos = 0.5 * ($(top).height() - headNnav_H - dialog.dialog.height()) + $(top).scrollTop() - 70;
        if (topPos < 0) p.top = topPos = 0;
        dialog.dialog.css({top: topPos });
    })();
    return dialog;
};
function clearLigerForm (formID) {
    var textField=$("#"+formID).find('.ui-textbox').not('[data-comboboxid]');
    var dateField=$("#"+formID).find('.ui-datepicker');
    var selectField=$("#"+formID).find('select');
    var comboField=$("#"+formID).find('.l-text-combobox [data-comboboxid]');
    var form = liger.get(formID);
    textField.each(function(index, el) {
        var textItem=liger.get($(this).attr('ligeruiid'));
        textItem.setValue("");
        form.hideFieldError($(this).attr('name'));
    });
    dateField.each(function(index, el) {
        var dateItem=liger.get($(this).attr('ligeruiid'));
        dateItem.setValue(null);
        form.hideFieldError($(this).attr('name'));
    });
    comboField.each(function(index, el) {
        if (!$(this).attr('ligeruiid')) return;
        var comboItem=liger.get($(this).attr('ligeruiid'));
        comboItem.clear();
        form.hideFieldError($(this).attr('name'));
    });
    selectField.each(function(index, el) {
        var selectItem=liger.get($(this).attr('ligeruiid'));
        if(selectItem.element.value!=" ") selectItem.setValue(" "); //select默认值是" "空字符串
        form.hideFieldError($(this).attr('name'));
        form.hideFieldError($(this).attr('name')+"_txt");
    });
}

function CreatUploadInputBox (options) {
    var _options={
        target: null, //css选择器，class or id | 如果没有指定target，返回组件本身，但不添加到DOM
        deletable: false,
        clearLine: false, //是否一行一个组件
        buttonText: "浏览",
        placeholder: "请选择文件",
        id: "", //如果target是多个，第一个是指定的id，其它id后面添加下标
        onDelete: null,
        onBeforeRender: null,
        onChange: null,
        finishClear: false
    };
    $.extend(true, _options, options);

    var idName="fileupload_" +new Date().getTime();
    if (_options.id) idName=_options.id;
    var fileUploadHtml=
        '<div class="fileUploadBox">\
        <span class="sq-button sq-button-hasicon fileupload-button">\
            <i class="sqBtnIco_32"></i><span class="buttonText">'+ _options.buttonText +'</span>\
            <input class="fileupload-input" id="'+ idName +'" type="file" name="'+ idName +'">\
        </span>\
        <span class="inputBox filenameBox placeholder" data-placeholder="'+_options.placeholder+'">'+ _options.placeholder +'</span>\
        <span class="sq-button-hasicon onlyicon deleteButton Hide"><i class="sqBtnIco_7"></i></span>\
        </div>';
    if (_options.target == null) {
        var $Html=$(fileUploadHtml);
        if (_options.clearLine) {
            $Html.css({
                display: 'block',
                margin: '0 2px 2px 0'
            });
        };
        _setEvents($Html);
        _setOptions($Html);
        return $Html;
    }else if (_options.target && $(_options.target) && $(_options.target).length > 0) {
        $(_options.target).each(function(index, el) {
            var $Html=$(fileUploadHtml);
            if ($(el).parents('.fileUploadBox').length>0 || $(el).find('.fileUploadBox').length>0) { //判断是否已经实例化
                $Html=_refreshHtml(el);
            }else if ($(el).is('input') && $(el).attr('type')=='file') {
                var $cloneInput=$(el).clone().show().addClass('fileupload-input');
                $Html.find('.fileupload-input').replaceWith($cloneInput);
                if ($(el).attr('id')==undefined) _addID ($Html, index, el);
                _trigger_onBeforeRender($Html);
                $(el).replaceWith($Html);
            }else if (!$(el).is('input')) {
                _addID ($Html, index, el);
                _trigger_onBeforeRender($Html);
                $(el).html($Html);
            };
            _setEvents($Html);
            _setOptions($Html);
        });
    }else{
        return;
    };
    function _setOptions(uploadBox) {
        $(uploadBox).find('[type="file"]')[0].uploadOptions = _options;
    }
    function _refreshHtml (targetEl) { //参数targetEl是原生html元素对象
        var $Html;
        if ($(targetEl).parents('.fileUploadBox').length>0) {
            $Html=$(targetEl).parents('.fileUploadBox')
        }else if ($(targetEl).find('.fileUploadBox').length>0){
            $Html=$(targetEl).find('.fileUploadBox')
        };
        if (_options.buttonText) $Html.find('.buttonText').html(_options.buttonText);
        if (_options.placeholder) $Html.find('.filenameBox').addClass('placeholder').html(_options.placeholder);
        $Html.find('.fileupload-input').val(null);
        return $Html;
    };
    function _trigger_onBeforeRender (uploadBox) {
        if (_options.onBeforeRender && $.type(_options.onBeforeRender)=='function') _options.onBeforeRender(uploadBox);
    };
    function _addID (uploadBox, index, el) {
        var ID=_options.target.slice(1) + '_' + (index + 1); //如果没有id，就用选择器和索引来指定id
        if (_options.id) {  //在有target的前提下，如果指定了id，第一项用指定id，其它id后面添加下标
            if(index == 0) ID=_options.id;
            if(index > 0) ID=_options.id + '_' + index;
        };
        uploadBox.find('.fileupload-input').attr({'id': ID, 'name': ID});
    };
    function _setEvents (uploadBox) {
        if (_options.deletable) _setDeletable (uploadBox);
        _viewUploadFileName (uploadBox);
        $(uploadBox).find('[type="file"]').on('uploaded', function(event) {
            if (_options.finishClear === true) {
                this.value = null;
                $(uploadBox).find('.filenameBox').addClass('placeholder').html(_options.placeholder);
            }
        });
    };
    function _setDeletable (uploadBox) {
        var $deleteButton=uploadBox.find('.deleteButton').removeClass('Hide');
        $deleteButton.click(function(event) {
            uploadBox.remove();
            if (_options.onDelete && $.type(_options.onDelete)=='function') _options.onDelete(uploadBox);
        });
    };
    function _viewUploadFileName (uploadBox) {
        var $uploadInput=uploadBox.find('[type=file]');
        $uploadInput.change(function(event) {
            var f=this.files;
            var temFile = null;
            var filenameBox=uploadBox.find('.filenameBox');
            if (f.length==0) {filenameBox.html(_options.placeholder).addClass('placeholder'); return;}
            for (var i = 0; i < f.length; i++) {
                temFile = f[i];
                filenameBox.html(temFile.name).removeClass('placeholder');
            };
            if (_options.onChange && $.isFunction(_options.onChange)) _options.onChange(event);
        });
    };
};
CreatUploadInputBox.clearPlaceholder = function (o) {
    var $target = $(o.target);
    if ($target.length == 0) return;
    // 清空文件
    $('.fileUploadBox', $target).find('[type="file"]').each(function(index, el) {
        $(el)[0].value = null;
    });
    // 清空placeholder
    var $filenameBox = $('.fileUploadBox', $target).find('.filenameBox');
    $filenameBox.addClass('placeholder').each(function(index, el) {
        $(el).html($(el).data('placeholder'));
    });
    // 清空fileIcon
    $('.fileUploadBox', $target).find('.fileIcon').remove();
}
function filter_autoComboboxData (key, combobox) {
    if (!combobox.initData) {combobox.initData = combobox.data};
    combobox.bind('clear', function () {
        combobox.setData(combobox.initData);
    });
    var filterRules = key ? [{
        field: combobox.options.textField,
        op: "like",
        type: "text",
        value: key
    }] : []
    var filterFunction = $.ligerFilter.getFilterFunction(filterRules);
    var newData = [];
    for (var i = 0; i < combobox.initData.length; i++) {
        if (filterFunction(combobox.initData[i])) {
            newData[newData.length] = combobox.initData[i]
        };
    };
    combobox.setData(newData);
};
var SQ = {
    tab_onceLoad: function (ligerTab) {
        var tabid_list = ligerTab.getTabidList(ligerTab.getSelectedTabItemID());
        var flag_tabLoaded = {};
        flag_tabLoaded[ligerTab.getSelectedTabItemID()] = true;
        $(tabid_list).each(function(i, el) {
            flag_tabLoaded[tabid_list[i]] = false;
        });
        ligerTab.bind('afterSelectTabItem', function(tabid) {
            if (!flag_tabLoaded[tabid]) {
                ligerTab.reload(tabid);
                flag_tabLoaded[tabid] = true;
            };
        });
    },
    tab_dropMenu: function (options) {
        if (!options) return;
        var pageInTab = options.ligerTab,
            tabid = options.tabid,
            items = options.items;
        $('[tabid='+tabid+']').find('a').append('<span class="sqIco sqIco_downArrow dropdown_btn"></span>');
        var h = '<ul class="tabDrop" id="tabDrop_'+ tabid +'">';
        $(items).each(function(i, item) {
            var activeCls = "";
            i == 0 ? activeCls = "active" : "";
            h += '<li class="'+ activeCls +'" data-target="'+ item.target +'"><span>'+ item.text +'</span></li>'
        });
        h += '</ul>';
        var $h = $(h);
        $("body").append($h);
        $('[tabid='+tabid+'] .dropdown_btn').click(function(event) {
            event.stopPropagation();
            if ($("#tabDrop_"+tabid).is(':hidden')) {
                _hide_dropMenu();
                _show_dropMenu(tabid);
            }else{
                _hide_dropMenu();
            };
        });
        $("li", $h).click(function(event) {
            $(this).addClass('active').siblings('li').removeClass('active');
            _hide_dropMenu();
            pageInTab.selectTabItem(tabid, true);
            pageInTab.setTabItemSrc(tabid, $(this).attr('data-target'));
        });
        $(document).click(function(event) {
            _hide_dropMenu();
        });
        function _show_dropMenu (tabid) {
            var offset = $("[tabid="+tabid+"]").offset();
            $("#tabDrop_"+tabid).show().css({
                left: offset.left,
                top: offset.top + $("[tabid="+tabid+"]").height(),
                width: $("[tabid="+tabid+"]").width()
            });
            $('[tabid='+tabid+'] .dropdown_btn').removeClass('sqIco_downArrow').addClass('sqIco_downArrowActive');
        }
        function _hide_dropMenu () {
            $(".tabDrop").hide();
            $(".pageInTab .dropdown_btn").removeClass('sqIco_downArrowActive').addClass('sqIco_downArrow');
        }
    },
    setIDs_onCheckTree: function (item, checked, tree, arr) {
        var idField = tree.options.idField || "id";
        setTimeout(function () {
            var checkNodes = getCheckNodes (item,checked);
            setRESOURCE_IDs (checkNodes, checked);
        }, 1);
        function setRESOURCE_IDs (checkNodes, ischecked) {
            if (ischecked) {
                for (var i = 0; i < checkNodes.length; i++) {
                    var checkedID=checkNodes[i][idField];
                    if(arr.indexOf(checkedID)==-1) arr.push(checkedID);
                };
            } else{
                for (var i = 0; i < checkNodes.length; i++) {
                    var checkedID=checkNodes[i][idField];
                    var index=arr.indexOf(checkedID);
                    if(index>=0) arr.splice(index,1);
                };
            };
        }
        // 获取tree check或uncheck的时候,触发的所有node，包括子节点
        function getCheckNodes (checkNode, ischecked) {
            var checkNodes = [],
                ligerTree = tree;
            //如果不是联动 或 半选择，只返回当前点击的checkNode
            if (!ligerTree.options.autoCheckboxEven || ligerTree.options.enabledCompleteCheckbox) {
                checkNodes.push(checkNode);
                return checkNodes;
            }
            function _findNodes (node) {
                checkNodes.push(node);
                if (ligerTree.hasChildren(node)) {
                    for (var i = 0; i < node.children.length; i++) {
                        var childrenNode=node.children[i];
                        _findNodes (childrenNode);
                    };
                }else{
                    return;
                };
            }
            function _findParentNodes(node) {
                var parentNode = ligerTree.getParent(node),
                    parentNodeItem = ligerTree.getParentTreeItem(node);
                if (!parentNodeItem) return;
                if (!ischecked && $('>.l-body .l-checkbox-checked', parentNodeItem).length) return;
                checkNodes.unshift(parentNode);
                if ($(parentNodeItem).attr('outlinelevel') != 1) {_findParentNodes(parentNode)};
            }
            _findParentNodes(checkNode.data);
            _findNodes (checkNode.data);
            return checkNodes;
        }
    },
    dropLinks: function (html) {
        return '<div class="dropLinks"><div class="dropBtn">更多</div><div class="dropList">' + html + '</div></div>';
    },
    previewGrid_s: function (gridID) {
        var g = liger.get(gridID),
            gData = g.rows,
            preData = {};
        if (gData.length == 0) {
            $.ligerDialog.SQalert({content: "没有可预览的数据!",SQ_type: "warning"});
            return;
        };
        _getPreviewData(gData);
        _showPreview(preData);
        function _getPreviewData(gData) {
            for (var i = 0; i < gData.length; i++) {
                var o = gData[i],
                    arr = [];
                var columns = g.columns;
                for (var j = 0;j < columns.length; j++) {
                    if (columns[j].name == undefined) continue;
                    var id = g.id + (g.options.frozen ? "|2|" : "|1|") + o.__id + '|' + columns[j].__id,
                        ctext = $(document.getElementById(id)).text().replace(/;/g, ",");
                    if (ctext == '' || ctext == undefined) continue;
                    arr.push(ctext);
                };
                if (arr[0] == undefined) arr[0] = ''; //至少第一项是非undefined
                if (preData[arr[0]]) {
                    preData[arr[0]].push(arr.slice(1));
                }else{
                    preData[arr[0]] = [];
                    preData[arr[0]].push(arr.slice(1));
                };
            };
        };
        function _showPreview(preData) {
            var htm = '<div class="previewGridWrap">';
            for(var key in preData){
                htm += '<div class="dl"><div class="dt">'+ key + ':';
                htm += '</div><div class="dd"><div class="ul">';
                for (var i = 0; i < preData[key].length; i++) {
                    htm += '<div class="li">' + (i+1) + '、 ' + preData[key][i].join(',') + '。</div>';
                };
                htm += '</div></div></div>';
            };
            htm += '</div>';

            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            $.ligerDialog.SQopen({
                width: 500,
                autoFixHeight: true,
                title : '预览',
                content: htm,
                buttons: [
                    {
                        text: "确定", onclick: onCancel, type: 'cancel'

                    }
                ]
            });
        };
    },
    validGrid: function (gridID) {
        //Grid的columns里要添加validate属性(函数)
        var g = liger.get(gridID),
            valids = [];
        for (var i = 0; i < g.rows.length; i++) {
            var row = g.rows[i];
            for (var j = 0; j < g.columns.length; j++) {
                if (!g.columns[j].validate) continue;
                var col = g.columns[j],
                    isValid = _validCell(row, col);
                valids.push(isValid);
            };
        };
        function _validCell(r, o) {
            var col_id = o.__id
            col_name = o.name;
            var $tipDOM = $(_getGridCellDOM(r, o)),
                validResult = o.validate(r[col_name],r,o);
            if (validResult === false || typeof validResult == "string"){
                $tipDOM.addClass('error');
                if (typeof validResult == "string") {
                    $tipDOM.attr('title', validResult).grid_ligerTip();
                };
                return false;
            }else{
                $tipDOM.removeClass('error');
                return true;
            };
        };
        function _getGridCellDOM(r, o) {
            var id = g.id + (g.options.frozen ? "|2|" : "|1|") + r.__id + '|' + o.__id;
            return $(document.getElementById(id));
        };
        g.bind('beforeEdit', function(e) {
            $(_getGridCellDOM(e.record, e.column)).ligerHideTip();
        });
        g.bind('afterEdit', function(e) {
            if (!e.column.validate) return;
            _validCell(e.record, e.column);
        });
        for (var i = 0; i < valids.length; i++) {
            if (valids[i] == false) return false;
        }
    },
    imgPreview: function(src, options) {
        var winOBJ = window,
            winPos = null, //winPos ：预览显示位置， 默认当前window框架，如果是true，就在第一层iframe里显示
            popHtml = '<div class="zoomImgWrap"><div class="mask"></div><div class="imgBox">' +
                '<img src="'+src+'">' +
                '</div></div>';
        var o = {
            closeBtn: true,
            onClose: null
        };
        $.extend(true, o, options);

        if (typeof options == "boolean") winPos = options;
        if (o.winPos) winPos = o.winPos;
        if (typeof winPos == "boolean" && winPos && window != top) {
            winOBJ = top.frames[top.tab.getSelectedTabItemID()];
        };
        var $pop = winOBJ.$(popHtml);
        if (o.closeBtn === true) {
            $pop.append('<span class="closeBtn sqiconfont">&#xe621;</span>');
        };
        winOBJ.$('body').append($pop);
        var startPos = 0;
        if (window != top) {
            if (parent.pageInApp && winPos !== true) startPos += 48;//48是二级标签加padding的值
            if (top.mainApp && top.headNnav_H) startPos += top.headNnav_H;
        };
        $('.imgBox', $pop).css({
            'height': $(top).height() - startPos - 1,
            marginTop: window == top ? 0 : $(top).scrollTop()
        });
        $('.closeBtn', $pop).css({
            marginTop: window == top ? 0 : $(top).scrollTop()
        });
        $('.imgBox img', $pop).smartZoom({'containerClass':'zoomableContainer'});
        $('.closeBtn, .mask', $pop).on('click', function(event) {
            // $('.imgBox img', $pop).smartZoom("destroy");
            // $pop.remove();
            r.close();
            if (o.onClose && $.isFunction(o.onClose)) o.onClose();
        });
        var r = {
            close: function () {
                $('.imgBox img', $pop).smartZoom("destroy");
                $pop.remove();
            }
        };
        return r;
    },
    scanCode: function (options) { //依赖 SQ.imgPreview 方法
        var o = {
            message : "注意：扫码时请保证鼠标焦点在此输入框内。",
            href: null,
            onScan: null
        };
        $.extend(true, o, options);
        if (!o.href) return;
        // var preview = SQ.imgPreview(o.href, {closeBtn: false});
        var preview = SQ.imgPreview(o.href,{
            onClose: function () {
                r.close();
            }
        });
        var $obj = $('<div class="codeWrap"><input type="password" class="barCodeArea"><div class="noticeBox">'+o.message+'</div></div>').appendTo('body');
        $obj.css('top', window == top ? 10 : $(top).scrollTop() + 10);
        $obj.find('input').trigger('focus').on('keydown', function(event) {
            if(event.keyCode==13) {
                if ($.isFunction(o.onScan)) {
                    o.onScan(this.value);
                }else {return}
            };
        });
        var r = {
            close: function () {
                preview.close();
                $obj.remove();
            }
        };
        return r;
    },
    //弹出新window窗口展示图片，依赖sq_iviewer
    img_winopen: function (options) {
        var _srcWin = options.srcWin;
        $('[role="winOpen"]').on('click', function(event) {
            event.preventDefault();
            var imgSrc = $(event.target).attr('src'),
                imgTit = $(event.target).attr('title');
            window.__ImgSrc = imgSrc;
            window.__ImgTit = imgTit;
            window.open(_srcWin, '_blank', 'location=yes, resizable=yes, width=800, height=600, left=500, top=500');
        });
    },
    add_tabFlasher: function (options) {
        if (!options) return;
        var pageInTab = options.ligerTab,
            tabid = options.tabid,
            tip = options.tip,
            $flasher = $('<i class="flasher ico_flasher"></i>');
        if (tip) {
            $flasher.attr('title', tip);
        }
        $('.l-tab-links [tabid='+tabid+']', pageInTab.element).find('a').prepend($flasher);
        $flasher.ligerTip();
    }
};
SQ.utils = {
    currencyFormatter : function(num, precision){
        var cents, sign;
        if (!num) num = 0;
        num = num.toString().replace(/\$|\,/g, '').replace(/[a-zA-Z]+/g, '');
        if (num.indexOf('.') > -1) num = num.replace(/[0]+$/g, '');
        if (isNaN(num))
            num = 0;
        sign = (num == (num = Math.abs(num)));

        if (precision == null)
        {
            num = num.toString();
            cents = num.indexOf('.') != -1 ? num.substr(num.indexOf('.') + 1) : '';
            if (cents)
            {
                num = Math.floor(num * 1);
                num = num.toString();
            }
        }
        else
        {
            precision = parseInt(precision);
            var r = Math.pow(10, precision);
            num = Math.floor(num * r + 0.50000000001);
            cents = num % 100;
            num = Math.floor(num / r).toString();
            while (cents.toString().length < precision)
            {
                cents = "0" + cents;
            }
        }
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3) ; i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
                num.substring(num.length - (4 * i + 3));
        var numStr = "" + (((sign) ? '' : '-') + '' + num);
        if (cents) numStr += ('.' + cents);
        return numStr;
    },
    dataToFix : function () {
        $('[data-tofix]').each(function(index, el) {
            var Precision = $(this).data('tofix');
            $(this).toFixNumber(Precision,
                {
                    onToFix: function () {
                        top.$.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不能超过"+Precision+"位数！"});
                    }
                }
            );
        });
    }
};
SQ.regs ={
    img: /^.*\.(?:png|jpg|bmp|gif|jpeg|tiff)$/i
};
(function($){
    $.fn.setDisabled_ligerRadio = function(a){
        this.each(function(index, el) {
            var ligeruiid=$(el).attr('ligeruiid');
            if (!ligeruiid) return;
            if (a === true) {
                liger.get(ligeruiid).setDisabled();
            }else if(a === false){
                liger.get(ligeruiid).setEnabled();
            };
        });
    };
    $.fn.setDisabled_ligerTextarea = function(a){
        if (a === true) {
            this.attr('readonly', true).addClass('textarea-disabled');
        }else if(a === false){
            this.attr('readonly', false).removeClass('textarea-disabled');
        };
    };
    //grid表格内部，添加ligerTip（render的时候必须嵌套一层）
    $.fn.grid_ligerTip = function(){
        this.each(function(index, el) {
            var distanceX=0,
                gridTip_position = 'right',
                this_W=$(this).width(),
                parent_W=$(this).parent().width();
            if (this_W > parent_W) distanceX=parent_W - this_W;
            var tip_rightPosition=$(this).offset().left + $(this).width() + 170;
            if (tip_rightPosition > $(window).width()) gridTip_position = 'left';
            $(this).ligerHideTip();
            $(this).ligerTip({
                distanceX: distanceX + 3,
                distanceY: -3,
                auto: true,
                position: gridTip_position
            });
        });
    };
    $.fn.show_ligerComboItems = function(wrapper){ //指定items放入的容器
        var combo_Mng=this.ligerGetComboBoxManager(),
            combo_texts=combo_Mng.getText().split(';'),
            combo_texts_h='';
        for (var i = 0; i < combo_texts.length; i++) {
            combo_texts_h += '<li>' + combo_texts[i] + '</li>';
        };
        combo_texts_h = '<ul class="combo_itemList">' + combo_texts_h + '</ul>';
        if (wrapper && typeof wrapper == 'string') {
            this.parents('.l-text-wrapper').siblings(wrapper).find(".combo_itemList").remove();
            if (combo_texts.length == 1 && combo_texts[0] == "") return;
            this.parents('.l-text-wrapper').siblings(wrapper).css('display', 'block').html(combo_texts_h);
        } else{
            this.parents('.l-text-wrapper').next(".combo_itemList").remove();
            if (combo_texts.length == 1 && combo_texts[0] == "") return;
            this.parents('.l-text-wrapper').after(combo_texts_h);
        };
    };
    $.fn.add_ligerFormEditor = function(callback){ //动态添加表单元素，并返回新加元素的control
        if (this.length == 0) return;
        var that = this;
        var this_editor = null;
        var this_ligerForm=liger.get(this.parents("form").attr('ligeruiid'));
        $.each(this_ligerForm.autoEditors, function(index, el) {
            if (that.attr("name") == el.name) {
                this_editor = el;
            }
        });
        if (this_editor) return this_editor.control; //如果已经实例化，就返回它的control
        this_editor=$.ligerDefaults.Form.editorBulider.call({options: {inputWidth: 180}}, this);
        this_ligerForm.autoEditors.push(this_editor);
        if (callback && typeof callback == 'function') callback(this_editor.control);
        SetIframe_height();
        return this_editor.control;
    };
    $.fn.remove_ligerFormEditor = function(){ //单独制定删除liger表单对象，包括HTML元素
        if (this.length == 0) return;
        var that = this;
        var this_form = this.parents("form");
        var this_ligerForm=liger.get(this_form.attr('ligeruiid'));
        var editors = this_ligerForm.autoEditors;
        for (var i = 0; i < editors.length; i++) {
            if (this.attr('name') == editors[i].name) {
                editors[i].control.destroy();
                _removeElements(editors[i]);
                editors.splice(i, 1);
                i--;
            };
        };
        function _removeElements (editor) {
            switch(editor.control.type){
                case "ComboBox":
                    if (that.css('display') == 'none') {
                        that.next('.l-text-wrapper').remove();
                        that.remove();
                    }else if(that.prop('readonly')){
                        that.parents('.l-text-wrapper').remove();
                    };
                    break;
                case "Radio":
                    that.parents('.l-radio-wrapper').remove();
                    break;
                case "DateEditor":
                    that.parents('.l-text-wrapper').remove();
                case "TextBox":
                    that.parents('.l-text').remove();
                    break;
                default:
                    that.remove();
            }
        }
    };
    $.fn.check_ligerFormEditor = function(){ //1，新增的元素liger实例化；2，删除的元素从autoEditors数组中移除
        if (this.length == 0) return;
        var that = this;
        var this_ligerForm=liger.get(this.attr('ligeruiid'));
        var editors = this_ligerForm.autoEditors;
        for (var i = 0; i < editors.length; i++) { //清理autoEditors中的ligerForm对象，并destroy
            (function () {
                var $editor = that.find('[name='+editors[i].name+']');
                if ($editor.filter('[ligeruiid]').hasClass('newEditor')) { //初始化没能清除".newEditor"的case
                    $editor.removeClass('newEditor');
                };
                if ($editor.length == 0 || $editor.not('[ligeruiid]').hasClass('newEditor')) { //无对应元素 || 重新加载后重复的组件（样式没刷新）的case
                    if(editors[i].control.type) editors[i].control.destroy();
                    editors.splice(i, 1);
                    i--;
                };
            })();
        };
        this.find("input, select, textarea").each(function(index, el) { //当有新的还没实例化成为ligerForm对象的，全部实例化
            if ($(el).hasClass('newEditor') && !_isLigerFormEditor(el)) {
                $(el).removeClass('newEditor').add_ligerFormEditor();
            }
        });
        SQ.utils.dataToFix();
        function _isLigerFormEditor (el) {
            var result = false;
            for (var i = 0; i < editors.length; i++) {
                if ($(el).attr('name') == editors[i].name) result = true;
            };
            return result;
        };
    };
    $.fn.pageInSideLink = function(o){
        if ($('li.active', this).length != 1) {
            if (o && o.currentNav) {
                $('#'+o.currentNav).addClass('active');
            }else{
                $('li:first-child', this).addClass('active');
            };
        };
        $('li', this).each(function(index, el) {
            $(el).on('click', function(event) {
                var src = $(this).data('src');
                if (!src) return;
                if (parent.pageInApp && parent.pageInApp.pageInTab) {
                    var curTabID = parent.pageInApp.pageInTab.getSelectedTabItemID();
                    parent.pageInApp.pageInTab.setTabItemSrc(curTabID, src);
                }else if(parent.mainApp && parent.mainApp.parentTab){
                    var curTabID = parent.mainApp.parentTab.getSelectedTabItemID();
                    parent.mainApp.parentTab.setTabItemSrc(curTabID, src);
                };
            });
        });
    };
    //小数点后超过指定长度时，限制输入
    $.fn.toFixNumber = function (Precision, options) {
        var precision = Precision ? Precision : 2;
        var p = {
            onToFix: function () {
                // alert('小数点后面最多'+ precision +'位！');
            }
        };
        $.extend(true, p, options);
        $(this).bind('keyup change', function(event) {
            var value = $(this).val();
            var _reg_toFix  = new RegExp('(\\.[0-9]{'+ (precision+1) +'})'),
                _reg_toFix2 = new RegExp('(^[0-9]*\\.[0-9]{'+ precision +'})([0-9]*)$');
            if (_reg_toFix.test(value)) {
                if (p.onToFix && (typeof p.onToFix == "function")) p.onToFix();
                $(this).val(value.replace(_reg_toFix2, "$1"));
            }
        });
    };
    $.fn.setFull_height = function (diff_height) {
        var this_offsetTop = $(this).offset().top,
            diff_H = diff_height ? diff_height : 0;
        $(this).height($(window).height() - this_offsetTop - 30 + diff_H);
    };
    $.fn.afterUploadFile = function (options) {
        var o = {
            filenameField: 'fileNm',
            filePathField: 'filePath',
            files_DATA: null,
            multi: false,
            onDelete: null
        };
        $.extend(true, o, options);
        if (!o.files_DATA || o.files_DATA.length == 0) return;
        var that = this,
            DATA = o.files_DATA;
        if (o.multi) {
            // 单个组件 多个上传时
            var fileInput = this[0];
            var $filesList;
            setTimeout(function () {
                var $fileBtn = $(fileInput).parents('.fileupload-button');
                if ($fileBtn.prev('.FilesList').length > 0) {
                    $filesList = $fileBtn.prev('.FilesList')
                } else {
                    $filesList = $('<ul class="FilesList"></ul>');
                    $fileBtn.before($filesList);
                };
                for (var i = 0; i < DATA.length; i++) {
                    var fileName = DATA[i][o.filenameField];
                    var $fileItem = $('<li><span class="count"></span><span class="fineName">'+fileName+'</span></li>').appendTo($filesList);
                    $fileItem.data('filedata', DATA[i]);
                    _setCount();
                    _setIcons($fileItem, DATA[i][o.filenameField], DATA[i][o.filePathField]);
                };
                SetIframe_height();
                fileInput.value = null;
            }, 100);
            function _setCount() {
                $filesList.find('li .count').each(function(index, el) {
                    $(el).html(index + 1 + ')&nbsp;&nbsp;');
                });
            }
            function _setIcons(filebox, filename, filePath) {
                var iconClass = SQ.regs.img.test(filename) ? 'sqBtnIco_52' : 'sqBtnIco_8';
                var $icons = $('<div class="icons"><a class="fileIcon" href="'+filePath+'"><span class="sq-button-hasicon onlyicon"><i class="'+ iconClass +'"></i></a></span><span class="sq-button-hasicon onlyicon deleteButton"><i class="sqBtnIco_7"></i></span></div>').appendTo(filebox);
                if (SQ.regs.img.test(filename)) {
                    $('.fileIcon', $icons).click(function(event) {
                        event.preventDefault();
                        SQ.imgPreview($(this).attr('href'), true);
                    });
                }else{
                    $('.fileIcon', $icons).click(function(event) {
                        event.preventDefault();
                        window.open($(this).attr('href'));
                    });
                };
                $('.deleteButton', $icons).click(function(event) {
                    var $li = $(this).parents('li');
                    var fileData = $li.data('filedata');
                    if ($.isFunction(o.onDelete)) {
                        o.onDelete(fileData, __removeFile);
                    };
                    function __removeFile() {
                        $li.remove();
                        _setCount();
                    };
                });
            };
        } else {
            // 单个组件单个上传时
            setTimeout(function () {
                //需要等上传插件还原input，因此setTimeout
                var $fileBox = that.parents('.fileUploadBox');
                var fileName = that[0].files[0] && that[0].files[0].name;
                if (!fileName) return;
                if ($.isArray(DATA)) {
                    for (var i = 0; i < DATA.length; i++) {
                        var fileName_D = DATA[i].fileNm;
                        if (fileName == fileName_D) {
                            _addToIcon($fileBox, DATA[i][o.filenameField], DATA[i][o.filePathField]);
                        };
                    };
                } else if ($.isPlainObject(DATA)) {
                    _addToIcon($fileBox, DATA[o.filenameField], DATA[o.filePathField]);
                }
            }, 100);
            function _addToIcon(filebox, filename, filePath) {
                var iconClass = SQ.regs.img.test(filename) ? 'sqBtnIco_52' : 'sqBtnIco_8';
                filebox.find('.fileIcon').remove();
                var $fileIcon = $('<a class="fileIcon" href="'+filePath+'"><span class="sq-button-hasicon onlyicon"><i class="'+ iconClass +'"></i></span></a>').appendTo(filebox);
                if (SQ.regs.img.test(filename)) {
                    $fileIcon.click(function(event) {
                        event.preventDefault();
                        SQ.imgPreview($(this).attr('href'), true);
                    });
                }else{
                    $fileIcon.click(function(event) {
                        event.preventDefault();
                        window.open($(this).attr('href'));
                    });
                };
            };
        };
    };
    $.fn.remove_afterUploadIcon = function () {
        this.parents('.fileUploadBox').find('.fileIcon').remove();
    };
    //合并ligerGrid指定列同名单元格
    $.fn.rowspan_S = function (colname, gridid) {
        var colIdx,
            Grid = liger.get(this[0].id)
        tableBody = this.find('.l-grid-body-table tbody');
        console.log(Grid);
        for (var i = 0, n = Grid.columns.length; i < n; i++) {
            if (Grid.columns[i]["columnname"] == colname) {
                // colIdx = i - 1 < 1 ? 0 : i - 1;
                colIdx = i;
                if (Grid.options.frozen) {
                    var frozenTdLength = Grid.gridview1.find('.l-grid-body-table tr:first-child td').length;
                    colIdx = i - frozenTdLength; //To do : columns设置里面有frozen:true会出bug
                };
                break;
            }
        };
        return tableBody.each(function () {
            var that;
            $('tr', this).each(function (row) {
                $('td:eq(' + colIdx + ')', this).filter(':visible').each(function (col) {
                    if (that != null && $(this).html() == $(that).html()) {
                        rowspan = $(that).attr("rowSpan");
                        if (rowspan == undefined) {
                            $(that).attr("rowSpan", 1);
                            rowspan = $(that).attr("rowSpan");
                        }
                        rowspan = Number(rowspan) + 1;
                        $(that).attr("rowSpan", rowspan);
                        $(this).hide();
                    } else {
                        that = this;
                    }
                });
            });
        });
    };
    $.fn.rowspan = function (colname, gridid) {
        var colID,
            Grid = liger.get(this[0].id)
        tableBody = this.find('.l-grid-body-table tbody');
        for (var i = 0, n = Grid.columns.length; i < n; i++) {
            if (Grid.columns[i]["columnname"] == colname) {
                colID = Grid.columns[i].__id;
                break;
            }
        };
        return tableBody.each(function () {
            var that;
            $('tr', this).each(function (row) {
                $('td[id$='+colID+']',this).each(function (col) {
                    if (that != null && $(this).html() == $(that).html()) {
                        rowspan = $(that).attr("rowSpan");
                        if (rowspan == undefined) {
                            $(that).attr("rowSpan", 1);
                            rowspan = $(that).attr("rowSpan");
                        }
                        rowspan = Number(rowspan) + 1;
                        $(that).attr("rowSpan", rowspan);
                        $(this).empty().hide();
                    } else {
                        that = this;
                    }
                });
            });
        });
    };
})(jQuery);

//添加ligerui组件的方法
(function ($) {
    $.ligerui.controls.Tree.prototype.getCheckedDataBy = function (parm) {
        var g = this, p = this.options;
        if (!this.options.checkbox) return null;
        var checkedData = g.getCheckedData(),
            values = [];
        for (var i = 0; i < checkedData.length; i++) {
            values.push(checkedData[i][parm]);
        };
        return values;
    }
})(jQuery);